package Evaluation;

import java.util.*;

import weka.core.*;

public class ClusterResultMap {
	/*integer is the index of cluster. ArrayList contains the index of test case of
	 * the corresponding cluster*/
	Map<Integer, ArrayList<Integer>> m;
	
	int clusterAttIndex;
	
	ClusterResultMap(int clusterAttIndex){
		this.clusterAttIndex = clusterAttIndex;
		m = new HashMap<Integer, ArrayList<Integer>>();
	}
	
	public HashMap<Integer, ArrayList<Integer>> clusterResultMap(Instances result){
		double[] d = result.attributeToDoubleArray(this.clusterAttIndex);
		int[] i = new int[d.length];
		for(int j = 0; j < d.length; j++){
			i[j] = (int)d[j];
		}
		for(int ins = 0; ins < i.length; ins++){
			
			if(m.containsKey(i[ins])){
				m.get(i[ins]).add(ins);
			}
			else{
				ArrayList<Integer> a = new ArrayList<Integer>();
				a.add(ins);
				m.put(i[ins], a);
			}
		}
		
		return (HashMap<Integer, ArrayList<Integer>>) m;
	}
	
	public Map<Integer, ArrayList<Integer>> getMap(){
		return m;
	}
}
